﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class WiringHelp : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{

    private Texture2D TargetCursor;
    public AssemblyRun assemblyRun;
    // Use this for initialization
    void Start()
    {
        assemblyRun = GameObject.Find("AssemblyRun").GetComponent<AssemblyRun>();
    }

    // Update is called once per frame
    void Update()
    {

    }

    //鼠标指向原理图导线，当前连接的端子闪烁提示
    public void OnPointerEnter(PointerEventData eventData)
    {
        TargetCursor = Resources.Load("Cursor/TargetCursor1", typeof(Texture2D)) as Texture2D;
        Cursor.SetCursor(TargetCursor, Vector2.zero, CursorMode.Auto);
        if (!assemblyRun.wiringObjects[assemblyRun.wiringIndex][2].GetComponent<ObjTwinking>())
        {
            assemblyRun.wiringObjects[assemblyRun.wiringIndex][2].AddComponent<ObjTwinking>();
            assemblyRun.wiringObjects[assemblyRun.wiringIndex][3].AddComponent<ObjTwinking>();
//Debug.Log("wiringhelp:"+assemblyRun.wiringObjects[assemblyRun.wiringIndex][2].name);
        }

    }
    //鼠标离开原理图导线，当前连接的端子取消提示
    public void OnPointerExit(PointerEventData eventData)
    {
        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
        Destroy(assemblyRun.wiringObjects[assemblyRun.wiringIndex][2].GetComponent<ObjTwinking>());
        Destroy(assemblyRun.wiringObjects[assemblyRun.wiringIndex][3].GetComponent<ObjTwinking>());
        SetRenderor(assemblyRun.wiringObjects[assemblyRun.wiringIndex][2]);
        SetRenderor(assemblyRun.wiringObjects[assemblyRun.wiringIndex][3]);

    }

    void SetRenderor(GameObject obj)
    {
        Renderer renderor = obj.GetComponent<Renderer>();
        renderor.material.color = new Color(renderor.material.color.r, renderor.material.color.g, renderor.material.color.b, 0f);
    }

}
